import React, { Component } from 'react';
import { index_goodlist } from '../utils/api'
import './goodlist.scss'
class Goodlist extends Component {
    constructor(props) {
        super(props)
        this.state = {
            goodlist: []
        }
    }
    componentDidMount() {
        index_goodlist({ count: 9 }).then((res) => {
            console.log(res.data.list)
            this.setState({
                goodlist: res.data.list
            })
        })
    }
    render() {
        return (
            <div className='goodlist'>
                {
                    this.state.goodlist.map((item, index) => {
                        return (
                            <div className='goods1' key={index}>
                                <img src={item.pic} alt="" />
                                <p className="name">{item.name}</p>
                                <p className="price">
                                    <span>{item.salesPrice.name}</span>
                                    {/* 通过取整去清除获取的数据后面的小数 */}
                                    <span>￥{Math.floor(item.salesPrice.value)}</span>
                                </p>
                            </div>
                        )
                    })
                }

            </div>
        );
    }
}

export default Goodlist;